package com.cinyi.cyds.base.module;

import java.util.HashMap;
import java.util.Map;

public class ModuleManager
{
    private static ModuleManager instance = new ModuleManager() ;
    private Map<String,BaseModule> modules = new HashMap<String,BaseModule>();
    private ModuleManager()
    {
    }
    
    public static ModuleManager getInstance(){
        return instance;
    }
    
    public void reg(BaseModule module) throws ModuleNotSupportException{
        if(module == null||!module.enabled()){
            throw new ModuleNotSupportException("Module error OR not supported:" + module.getName() ) ;
        }
        modules.put(module.getName(), module);
    }
    
    public void removeModule(String name){
        modules.remove(name);
    }
    
    public void destory(){
        for (Map.Entry<String, BaseModule> entry : modules.entrySet()) {  
            entry.getValue().destroy();
        }  
    }

}
